
typedef unsigned char  Uint8;
typedef unsigned short Uint16;
typedef unsigned int   Uint32;

typedef char  Int8;
typedef short Int16;
typedef int   Int32;

#define F_RELFLG  (1<<0)
#define F_EXEC    (1<<1)
#define F_LNNO    (1<<2)
#define F_LSYMS   (1<<3)
#define F_LITTLE  (1<<8)
#define F_BIG     (1<<9)

#pragma pack(1)

typedef struct tagImageCoffHeader
{
	Uint16 file_ver_id;
	Uint16 sec_hdr_num;
	Uint32 time_stamp;
	Uint32 sym_tbl_base;
	Uint32 sym_tbl_cons;
	Uint16 opt_hdr_size;
	Uint16 flag;
	Uint16 target_id;
}IMAGE_COFF_HEADER;


typedef struct tagImageOptionalHeader
{
	Uint16 magic_number;
	Uint16 ver_stamp;
	Uint32 text_size;
	Uint32 data_size;
	Uint32 bss_size;
	Uint32 entry_point;
	Uint32 text_base;
	Uint32 bss_base;
}IMAGE_OPTIONAL_HEADER;

#define STYP_REG      0
#define STYP_DSECT    (1<<0)
#define STYP_NOLOAD   (1<<1)
#define STYP_COPY     (1<<4)
#define STYP_TEXT     (1<<5)
#define STYP_DATA     (1<<6)
#define STYP_BSS      (1<<7)
#define STYP_BLOCK    (1<<12)
#define STYP_PASS     (1<<13)
#define STYP_CLINK    (1<<14)
#define STYP_VECTOR   (1<<15)
#define STYP_PADDED   (1<<16)

typedef struct tagImageSectionHeader
{
	Uint8  sec_name[8];
	Uint32 sec_phy_addr;
	Uint32 sec_vir_addr;
	Uint32 sec_size;
	Uint32 raw_data_ptr;
	Uint32 relo_data_ptr;
	Uint32 line_ptr;
	Uint32 relo_num;
	Uint32 line_num;
	Uint32 flag;
	Uint16 reserve;
	Uint16 mem_page;
}IMAGE_SECTION_HEADER;


#define R_ABS       0000h
#define R_RELBYTE	000Fh
#define R_RELWORD	0010h
#define R_RELLONG	0011h
#define R_C60BASE	0050h
#define R_C60DIR15	0051h
#define R_C60PCR21	0052h
#define R_C60PCR10	0053h
#define R_C60LO16	0054h
#define R_C60HI16	0055h
#define R_C60SECT	0056h
#define R_C60S16	0057h
#define R_C60PCR7	0070h
#define R_C60PCR12	0071h
#define RE_ADD	4000h
#define RE_SUB	4001h
#define RE_NEG	4002h
#define RE_MPY	4003h
#define RE_DIV	4004h
#define RE_MOD	4005h
#define RE_SR	4006h
#define RE_ASR	4007h
#define RE_SL	4008h
#define RE_AND	4009h
#define RE_OR	400Ah
#define RE_XOR	400Bh
#define RE_NOTB	400Ch
#define RE_ULDFLD	400Dh
#define RE_SLDFLD	400Eh
#define RE_USTFLD	400Fh
#define RE_SSTFLD	4010h
#define RE_XSTFLD	4016h
#define RE_PUSH	4011h
#define RE_PUSHSV	c011h
#define RE_PUSHSK	4012h
#define RE_PUSHUK	4013h
#define RE_PUSHPC	4014h
#define RE_DUP	4015h

typedef struct tagImageRelocationEntry
{
	Uint32 va_ref;
	Uint16 sym_tbl_index;
	Uint16 resever;
	Uint16 relo_type;
}IAMGE_RELOCATION_ENTRY;


typedef struct tagImageSymbolTable
{
	Uint8  name[8];
	Uint32 sym_val;
	Uint16 sym_sec_num;
	Uint16 type_spec;
	Uint8  strg_class;
	Uint8  aux_entry_num;
}IMAGE_SYMBOL_TABLE;


typedef struct tagImageLineTable
{
	union{
		Uint32 sym_tbl_index;
		Uint32 pa_line;
	};

	Uint16 line_num;
	
}IMAGE_LINE_TABLE;
